home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-06-19 | 4.7 KB | 174 lines |
- package symantec.itools.awt;
-
-
- import java.net.URL;
- import java.awt.Event;
- import java.awt.Container;
- import java.applet.*;
-
-
- /**
- * Use this component to create an invisible rectangular button, usually within
- * an image, that links to a URL address when clicked. Specifically, use
- * InvisibleHTMLLink to:
- * <UL>
- * <DT>╖ Accept or yield focus.</DT>
- * <DT>╖ Respond to a user event.</DT>
- * <DT>╖ Send an action event to another component.</DT>
- * </UL>
- * Button tips:
- * <UL>
- * <DT>╖ Buttons accept and yield focus automatically by default.</DT>
- * <DT>╖ Buttons accept clicked events automatically by default.</DT>
- * <DT>╖ To send an action event to another component, use the Interaction
- * Wizard. Optionally, you can override the InvisibleButtonÆs click event in
- * project source code.</DT>
- * </UL>
- * Implements the Runnable interface to support threads. An InvisibleHTMLLink
- * can be set from the Property List window to post continuous action events
- * when the button is clicked.
- * <p>
- * @version 1.0, Nov 26, 1996
- * @author Symantec
- */
- public class InvisibleHTMLLink
- extends InvisibleButton
- {
- /**
- * URL to show when the button is clicked.
- */
- protected URL url;
- /**
- * Applet context that shows the URL.
- */
- protected AppletContext context;
- /**
- * Frame specifier for showing a URL document in a browser or applet
- * viewer. It is interpreted as follows:
- * <UL>
- * <DT>"_self" show document in the current frame</DT>
- * <DT>"_parent" show document in the parent frame</DT>
- * <DT>"_top" show document in the topmost frame</DT>
- * <DT>"_blank" show document in a new unnamed toplevel window</DT>
- * <DT>all others show document in a new toplevel window with the given name</DT>
- * </UL>
- */
- protected String frame;
-
- /**
- * Constructs a default InvisibleHTMLLink.
- */
- public InvisibleHTMLLink()
- {
- frame = null;
- }
-
- /**
- * Returns the URL to show when the button is clicked.
- * @see #setURL
- */
- public URL getURL()
- {
- return url;
- }
-
- /**
- * Sets the URL to show when the button is clicked.
- * @param u the URL to show when the button is clicked
- * @see #getURL
- */
- public void setURL(URL u)
- {
- url = u;
- context = null;
- }
-
- /**
- * Sets the title displayed on the applet frame while showing
- * the URL.
- * @param f applet frame title
- * @see #getFrame
- */
- public void setFrame(String f)
- {
- frame = f;
- }
-
- /**
- * Returns the title that is displayed on the applet frame while showing
- * the URL.
- * @see #setFrame
- */
- public String getFrame()
- {
- return frame;
- }
-
- /**
- * Handles internal actions for this component.
- * This is a standard Java AWT method which usually gets called by the AWT
- * method handleEvent() in response to receiving an ACTION_EVENT event. In those
- * cases the o parameter contains the value in the event's arg field.
- *
- * @param e the event that caused this action
- * @param o the action
- * @return true if the action was handled
- * @see java.awt.Component#handleEvent
- */
- public boolean action(Event event, Object what)
- {
- if (context != null)
- {
- if (frame == null || frame.length() == 0)
- context.showDocument(url);
- else
- context.showDocument(url, frame);
-
- return true;
- }
-
- return false;
- }
-
- /**
- * Ensures that this component is laid out properly, as needed.
- * This is a standard Java AWT method which gets called by the AWT to
- * make sure this component and its subcomponents have a valid layout.
- * If this component was made invalid with a call to invalidate(), then
- * it is laid out again.
- *
- * It is overridden here to locate the applet containing this component.
- *
- * @see java.awt.Component#invalidate
- */
- public void validate()
- {
- // On validation, try to find the containing applet. If we can find
- // it, we don't bother doing the link...
- Container c;
-
- c = getParent();
-
- while (c != null)
- {
- if (c instanceof Applet)
- {
- setAppletContext(((Applet) c).getAppletContext());
- break;
- }
-
- c = c.getParent();
- }
- }
-
- /**
- * Sets the applet context to use for showing the URL.
- * @param c the applet context
- */
- protected void setAppletContext(AppletContext c)
- {
- context = c;
- }
- }
-
-